﻿using System;
using System.Threading;
using ConsoleApp.Job.TaskFramework;
using ConsoleApp.Rmq;
using ConsoleAppFramework.Util;

namespace ConsoleAppFramework.Job.TaskJob.队列消费
{
    public class Rmq测试消费任务 : TaskBase
    {
        public override void Execute()
        {
            Thread.Sleep(15000);
            //ConsoleHelper.WriteInfoLine($"Rmq信息{RmqQueueManager.GetNodesDetail()}");
            ConsoleHelper.WriteInfoLine($"队列中的消息总数{RmqQueueManager.GetQueueCount(RmqQueueManager.QueueName.测试)}");
            ConsoleHelper.WriteSuccessLine($"Rmq测试任务开始消费");
            while (true)
            {
                new Rmq测试任务消费_RMQ(RmqQueueManager.QueueName.测试).HandleOneMessage();
            }
        }
    }

    public class Rmq测试任务消费_RMQ : OneConsumerWorkerBase<string>
    {
        public Rmq测试任务消费_RMQ(string queueName)
        {
            Console.Title = queueName;
            this.QueueName = queueName;
        }

        public void Handler(string message)
        {
            HandleComingMessage(message);
        }

        protected override bool HandleComingMessage(string message)
        {
            try
            {
                ConsoleHelper.WriteSuccessLine($"消费成功{message}");
            }
            catch (Exception ex)
            {
                ConsoleHelper.WriteErrorLine(ex.ToString());
            }
            return true;
        }
    }
}
